<?php

// TOOLS
include_once "application/tools/Authentification.php";

class GrapheView {
	
	private $projects;
	private $project;

    public function render() {
        $this->renderContent();
        $this->deconnect();
    }

	public function deconnect() {
        Authentification::doDeconnect();
    }
    
    private function getProjectsForSelectedList($id, $display = true) {
        if ($display)
            echo '<select  style="display:none" id="' . $id . '" name="' . $id . '">';
        else
            echo '<select  id="' . $id . '" name="' . $id . '">';
    	$result = "";
    	foreach ($this->projects  as $project) {
    		$selected = ($project->getId() == $this->project->getId()) ? 'selected="selected" ' : "" ;
			$result .= '<option '.$selected .'value="' . $project->getId() . '" >' . $project->getProjectName() . '</option>';
    	}
    	echo $result . '
			</select>';
                        
    }
    
    public function renderContent() {
    	$this->projects = GrapheController::getProjects();
    	$this->project = GrapheController::getCurrentProject();
    	$columns = $this->project->getColumns();
    	
        ?>
        
        <div class="overlay-shadow" style='display: none;'></div>
	          <div class="overlay-chart-container ui-corner-all">
				<div class="overlay-chart-container-header ui-widget-header ui-corner-top">
					Clic droit sur l'image pour l'enregistrer
					<div class="ui-icon ui-icon-closethick"></div>
				</div>
				
		        <div class="overlay-chart-container-content ui-corner-bottom"></div>
	          </div>
        <div id="page-content">
                    <div id="projets">
                        <!--<h2>Liste des projets :</h2>-->
                        
        				<?php 
                        	$this->getProjectsForSelectedList("ddlProjects");
                        ?>

                        <button id="button-add">Ajouter des donn&eacute;es</button>

                        <div id="dialog-add">
                            <form id="form-add-csv" method="post" enctype="multipart/form-data" name="form-add-csv" >
                                <input id="action" name="action" type="hidden" value="save" />
                                <fieldset>
                                    

                                    <label for="select-project-add">S&eacute;lectionner un projet</label>
                                    
                                    <?php $this->getProjectsForSelectedList("select-project-add", false);?>
                                    <br/>
                                    <br/>
                                    <label for="select-project-type">Type de donn&eacute;es</label>
                                    <select id="select-project-type" name="select-project-type" >
                                        <option value="data">Donn&eacute;es  de la carte</option>
                                        <option value="service">Donn&eacute;es de service</option>
                                    </select>
                                    <br/>
                                    <label for="csv">Fichier CSV</label>
                                    <input id="csv" name="csv" type="file"  />
                                </fieldset>
                            </form>
                        </div>


                    </div>
                    
                    <div class='chart_wrap'>
                    	<input type='hidden' value='0' name='chartNumber' class='chartNumber' />
	                    <div id='chart_container_0' class="chart_container">
	                    	<div id="toolbar">
	                    		<div class="chart-toggle ui-icon ui-icon-arrowthickstop-1-n"></div>
	                    		<div class="ui-icon ui-icon-print"></div>
	                    		<div class="ui-icon ui-icon-image"></div>
	                    	</div>
	                        <div id="chart_0" class='chart'></div>
	                        <!--<img id="expand-v" src="public/img/expand.png" name="add" alt="" width="25" height="25" />-->
	                        <img id="expand-h_0" class="expand-h" src="public/img/expand-h.png" name="add" alt="" width="25" height="25" />
	                        
	                    </div>
	                    
	                    
	                    
	                    <div id="param-graphe_0" class='param-graphe'>
		                    <div>
		                    	<select id="ddlCards_0" class='ddlCards span2' multiple="multiple"><?php 
		                    		$cards = Project::getProjectCards($this->project->getTableName());
		                    		
		                    		foreach($cards as $card) {
		                    			echo '<option value="'.$card.'">'.$card.'</option>';	
		                    		} ?>
		                    	</select>
		                    </div>
		                    
	                        <div id="axis-y">
	                            <h3>Ordonn&eacute;es</h3>
	                            
	        <?php
		    	foreach($columns as $column)
		        {
		        	echo '<input type="checkbox" name="columns" value="'.$column->getColumnName().'" class="cbxChartColumns" />'.$column->getColumnUsualName().'<br />';
		        }
		        
		        echo '<input type="checkbox" name="columns" value="services_data" class="cbxChartColumns cbxServicesData" />Donn&eacute;e de services<br />'; ?>
	                
	                </div>
	                        <hr>
	                        <div id="chartType_0" class='chartType'>
	                            <h3>Type de graphe</h3>
	                            <input type="radio" name="chartType_0" value="courbe" <?php echo $this->project->getGrapheType() == Project::GRAPHE_COURBE ? "checked='checked'" : ""; ?> /> courbe<br />
	                            <input type="radio" name="chartType_0" value="nuage" <?php echo $this->project->getGrapheType() == Project::GRAPHE_POINT ? "checked='checked'" : ""; ?> /> nuage de points<br />
	                            <input type="radio" name="chartType_0" value="histo" <?php echo $this->project->getGrapheType() == Project::GRAPHE_HIST0 ? "checked='checked'" : ""; ?> /> histogramme<br />
	                        </div>
	                        
	                        <button class="resetChart ui-state-default ui-corner-all" type="button">Effacer le graphe</button>
	                        <button class="addChart ui-state-default ui-corner-all" type="button">Ajouter un graphe</button>
	                   <div id='param-date_0' class="param-date" >
	                       <hr />
	                            Date de d&eacute;but : <input id="date-start_0" class="date-start span2" type="text" name="date-start" /><br />
	                            Date de fin : <input id="date-end_0" class="date-end span2" type="text" name="date-end"/>
	                            <button class="bt-filter ui-state-default ui-corner-all" type="button">filtrer</button>
	                        </div>
	                    </div>
	
	                </div>
              </div>
              <!-- END CONTENT -->
              
              <div id="error-dialog" style="display: none">
                  Une erreur est survenue. L'action n'a pas pu &ecirc;tre r&eacute;alis&eacute;e.
              </div>

        <?php

    }
}

?>
